const http = require("http");
const app = require("./app");
const dotenv = require("dotenv");
const mongoose = require("mongoose");

dotenv.config({ path: "./config.env" });

const Local_DB = process.env.LOCAL_URL;
const DB = process.env.DATABASE_URL.replace(
  "<password>",
  process.env.DATABASE_PASSWORD
);

mongoose
  .connect(Local_DB, { useNewUrlParser: true, useUnifiedTopology: true })
  // .connect(Local_DB, { useNewUrlParser: true, useUnifiedTopology: true })
  .then((con) => {
    console.log("连接成功！");
  })
  .catch((error) => {
    console.log("Altas Cluster connection error", error);
  });

const port = process.env.PORT;

const server = http.createServer(app);

app.listen(port, () => {
  console.log(`Server running at ${port}/`);
});
